//
//  TYMusicTool.m
//  黑马音乐盒
//
//  Created by 翟天宇 on 15/11/28.
//  Copyright © 2015年 翟天宇. All rights reserved.
//

#import "TYMusicTool.h"
#import "TYMusic.h"
#import "MJExtension.h"

@implementation TYMusicTool

static NSArray *_musics;
static TYMusic *_playingMusic;

+ (void)initialize {
    _musics = [TYMusic objectArrayWithFilename:@"Music.plist"];
}

+(NSArray *)musics {
    return  _musics;
}

+(TYMusic *)playingMusic {
    return _playingMusic;
}

+(void)setPlayingMusic:(TYMusic *)playingMusic {
    assert(playingMusic);
    _playingMusic = playingMusic;
}

+(TYMusic *)nextMusic {
//1.获取当前正在播放的音乐
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    //2.获取下一首音乐
    //2.1索引加1
    currentIndex++;
    //2.2判断是否越界
    if (currentIndex > _musics.count - 1) {
        currentIndex = 0;
    }
    //2.3取出下一首音乐
    TYMusic *nextMusic = _musics[currentIndex];
    
    _playingMusic = nextMusic;
    
    return nextMusic;
    
}

@end
